package com.reference;

import com.paic.icore.test.demo.entity.User;

/**
 * describe:
 * 方法不能改变引用一个新对象
 *
 * @author huxingjie
 * @date 2021/12/15
 * @since 5.1
 */
public class ReferenceTest {
    public static void main(String[] args) {
        User user1 = new User("张三");
        User user2 = new User("李四");
        swap(user1, user2);
        System.out.println(user1.getName());
        System.out.println(user2.getName());
    }

    private static void swap(User user1, User user2) {
        User tmp = user1;
        user1 = user2;
        user2 = tmp;
        //user1.setName("user1");
        //user2.setName("user2");
        System.out.println(user1.getName());
        System.out.println(user2.getName());
    }
}

    